package com.kinghood.productcenter.common.model.dto.product;

import com.kinghood.productcenter.common.model.dao.base.BaseAttributeDO;
import com.kinghood.productcenter.common.model.dao.base.BaseAttributeLimitDO;
import com.kinghood.productcenter.common.model.dao.base.BaseAttributeValueDO;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2023-12-28 10:58
 **/
@Data
public class BaseProductDaoDTO implements Serializable {

    List<String> styleList = new ArrayList<>();
    List<String> skuCodeList = new ArrayList<>();

    List<BaseAttributeDO> attributeList = new ArrayList<>();
    List<BaseAttributeLimitDO> attributeLimitList = new ArrayList<>();
    List<BaseAttributeValueDO> attributeValueList = new ArrayList<>();
    Map<String, Long> styleMap = new HashMap<>();
    Map<String, Long> brandMap = new HashMap<>();
    Map<String, Long> goodsMap = new HashMap<>();
    Map<String, Long> categoryMap = new HashMap<>();
    Map<String, Long> supplierMap = new HashMap<>();

    Map<String, BaseAttributeDO> attributeMap = Collections.emptyMap();
    Map<Long, BaseAttributeLimitDO> attributeLimitMap = Collections.emptyMap();
    Map<Long, List<BaseAttributeValueDO>> attributeValueMap = Collections.emptyMap();

    public void handleMap() {
        if (!CollectionUtils.isEmpty(attributeList)) {
            attributeMap = attributeList.stream()
                    .collect(Collectors.toMap(BaseAttributeDO::getAttributeName, v -> v, (k1, k2) -> k2));
        }
        if (!CollectionUtils.isEmpty(attributeLimitList)) {
            attributeLimitMap = attributeLimitList.stream()
                    .collect(Collectors.toMap(BaseAttributeLimitDO::getAttributeId, v -> v, (k1, k2) -> k2));
        }
        if (!CollectionUtils.isEmpty(attributeValueList)) {
            attributeValueMap = attributeValueList.stream()
                    .collect(Collectors.groupingBy(BaseAttributeValueDO::getAttributeId));
        }
    }
}
